/**
* @description: 路由器信息完善
* @author: JiWei
* @remark:
**/
<template>
  <view class="router-wrap">
    <nav-bar class="header" back title="路由器信息完善" @goBack="goBack" />
    <view class="main-container">
        <plateTitle title="基本信息" :isRequired="false" class="plate-title" />
        <view class="base-info-container">
          <van-cell-group v-for="(item, index) in currentData.visibleProps" :key="index">
            <!-- 不可编辑框 -->
            <van-field v-model="item.value" v-if="item.elementType === 'TEXT'" :required="item.isRequired" readonly input-align="right" :value="item.value" :label="item.title" @click="checkInfo(item)"
                       :name="item.name" :rules="item.rules" error-message-align="right" />
            <!-- 弹出筛选框 -->
            <van-field v-if="item.elementType === 'PICKER'" :required="item.isRequired" readonly clickable input-align="right" right-icon="arrow" v-model="item.text" :label="item.title"
                       placeholder="点击选择" @click="checkPickerList(item)"  :name="item.name" :rules="item.rules" error-message-align="right" />
            <!-- 弹出日期筛选框 -->
            <van-field v-if="item.elementType === 'TIMEPICKER'" :required="item.isRequired" readonly clickable input-align="right" right-icon="arrow" v-model="item.text" :label="item.title"
                       placeholder="点击选择" @click="checkPickerList(item)"  :name="item.name" :rules="item.rules" error-message-align="right"  />
            <!-- 输入框 -->
            <van-field v-if="item.elementType === 'INPUT'" :required="item.isRequired" clickable input-align="right" :value="item.value" :label="item.title" placeholder="请输入"
                       @input="inputBlur($event, item)"  :name="item.name" :rules="item.rules" error-message-align="right"  />
            <!-- 输入带扫码 -->
            <van-field v-if="item.elementType === 'INPUT&SCAN'" :required="item.isRequired" input-align="right" right-icon="scan" @input="inputBlur($event, item)" @click-right-icon="scanQrcode(item)"
                       :value="item.value" :label="item.title" />
          </van-cell-group>
        </view>
        <plateTitle title="巡视信息" :isRequired="false" class="plate-title2" />
        <!-- 巡视照片 -->
       <view class="patrol-info-container">
        <view>设备照片</view>
        <van-divider dashed />
        <div class="image-wrap">
          <div class="image-list">
            <div
                class="upload-button"
                v-for="(imgItem, index) in files"
                :style="{'background-image': `url(${imgItem.bgImg})`}"
                @click.stop="imageHandle(imgItem, index, 'CHOOSE')"
            >
              <div v-if="imgItem.img" class="delete-icon" @click.stop="imageHandle(imgItem, index, 'DELETE')">×</div>
              <img v-if="imgItem.img" :src="imgItem.img" alt="" @click.stop="imageHandle(imgItem, index, 'PREVIEW')">
            </div>
          </div>
        </div>
      </view>
      <!-- 备注 -->
      <view class="remark-info-container">
        <view>备注</view>
        <van-divider dashed />
        <div class="remark-wrap">
          <textarea class="remark-text" v-model="currentData.otherProps.remark">
          </textarea>
        </div>
      </view>
      <view class="result-info-container">
        <van-cell-group v-for="(item, index) in currentData.tourInfoProps" :key="index">
          <!-- 不可编辑框 -->
          <van-field
              v-if="item.elementType === 'TEXT'"
              :required="item.isRequired"
              readonly
              input-align="right"
              :value="item.value"
              :label="item.title"
          />
        </van-cell-group>
      </view>
    </view>
    <van-button block @click="upload">保存</van-button>
    <!--选择器-->
    <van-popup v-model="showPicker" position="bottom">
      <van-picker
          ref="picker"
          :default-index="defaultPickerIndex"
          show-toolbar
          :columns="currentPickerList"
          cancel-button-text="清空"
          @confirm="pickerConfirm"
          @cancel="pickerEmpty"
          @change="pickerChange"
      />
      <van-field
          v-show="showCustomInput"
          v-model="customInput"
          placeholder="请输入"
          :border="true"
      />
    </van-popup>
    <!--时间选择器-->
    <van-popup v-model="showTimePicker" position="bottom">
      <van-datetime-picker
          v-model="currentDate"
          type="year-month"
          title="选择年月"
          :formatter="formatter"
          :min-date="minDate"
          show-toolbar
          cancel-button-text="清空"
          @confirm="pickerConfirm"
          @cancel="pickerEmpty"
      />
    </van-popup>
    <van-popup class="van-preview-wrap" v-model="showPreview" @click="showPreview = false">
      <van-swipe>
        <div v-for="(image, index) in files" :key="index">
          <van-swipe-item v-if="image.img" style="text-align: center;">
            <div style="width: 100%; text-align: center;">{{ image.previewName }}</div>
            <img :src="image.img" />
          </van-swipe-item>
        </div>
      </van-swipe>
    </van-popup>
  </view>
</template>
<script>
import wx from "../../../../static/common_js/jweixin_1.0.0";

let infoOptical_add = {
  otherProps: {
    "remark": "",        //备注
  },
  tourInfoProps: { // 显示的属性。包含巡视人和巡视时间
    "tourOperName": {
      title: "巡视人",
      keys: "tourOperName",
      value: "",
      isRequired: false,
      elementType: "TEXT"
    }, //设备名称
    "tourTimStr": {
      title: "巡视时间",
      keys: "tourTimStr",
      value: "",
      isRequired: false,
      elementType: "TEXT"
    },   //所属站点名称
  },
  hideProps:{
    "taskId":"task001",    //所属工单id    //必填
    "siteid": "s001",   //所属站点
    "sitename": "",   //所属站点
    "tourOperId": "2",      //巡检人ID  必填      userId放进来
    "tourOperName": "2",    //巡检人名称    必填       userName放进来
    "producerIdCustom": "", // 自定义设备厂家名称
    "modelnumberCustom": "" // 自定义设备型号名称
  },
  visibleProps:{
    "routerName": {
      title: "设备名称",
      keys: "routerName",
      value: "",
      isRequired: true,
      elementType: "TEXT"
    },   // 设备名称
    "parStationIdName": {
      title: '所属站点',
      keys: 'parStationIdName',
      value: '',
      text: "",
      isRequired: true,
      elementType: "TEXT",
      name:'sitename',
      rules:[{ required: true, trigger:'onSubmit'}]
    },   //所属站点名称
    "parRoom": {
      title: "所属机房",
      keys: "parRoom",
      value: "",
      text: "",
      isRequired: false,
      elementType: 'PICKER',
      optionsParams: { type: 'room' } // 获取options需要的参数
    }, //所属机房
    "parRack": {
      title: '所属机柜编号',
      keys: 'parRack',
      value: '',
      isRequired: true,
      elementType: "INPUT",
      name:'parRack',
      rules:[{ required: true, trigger:'onSubmit'}]
    },   //所属机柜编号
    "parRackScreen": {
      title: "所属机柜屏眉",
      keys: "parRackScreen",
      value: "",
      isRequired: true,
      elementType: 'INPUT',
      name:'parRackScreen',
      rules:[{ required: true, trigger:'onSubmit'}]
    }, //所属机柜屏眉
    "dspLevel": {
      title: "设备所属通信网等级",
      keys: "dspLevel",
      value: "",
      text: "",
      isRequired: true,
      elementType: 'PICKER',
      optionsParams: { type: 'level' }, // 获取options需要的参数
      rules:[{ required: true, trigger:'onSubmit'}]
    }, //所属机房
    "producerId": {
      title: "设备品牌",
      keys: "producerId",
      value: "",
      text: "",
      isRequired: true,
      elementType: "PICKER",
      optionsParams: {type: "router"}, // 获取options需要的参数
      name:'producerId',
      rules:[{ required: true, trigger:'onSubmit'}]
    },  //设备品牌
    "modelnumber": {
      title: "设备型号",
      keys: "modelnumber",
      value: "",
      text: "",
      isRequired: true,
      elementType: "PICKER",
      optionsParams: {type: "routermodel"}, // 获取options需要的参数
      name:'modelnumber',
      rules:[{ required: true, trigger:'onSubmit'}]

    }, //设备型号
    "equStatus": {
      title: "设备角色",
      keys: "equStatus",
      value: "",
      isRequired: true,
      elementType: "PICKER",
      optionsParams: {type: "DEVICE_ROLE"}, // 获取options需要的参数
      name:'equStatus',
      rules:[{ required: true, trigger:'onSubmit'}]
    },   // 设备角色
    "serilanum": {
      title: "设备顺序",
      keys: "serilanum",
      value: "",
      text: "",
      isRequired: true,
      elementType: "PICKER",
      optionsParams: {type: "seril"}, // 获取options需要的参数
      rules:[{ required: true, trigger:'onSubmit'}]
    },   //设配顺序
    "picture": {
      title: "实物ID",
      keys: "picture",
      value: "",
      isRequired: false,
      elementType: 'INPUT&SCAN'
    }, //实物ID
    begTim: {
      title: '设备投运时间',
      keys: 'begTim',
      value: '',
      text: '',
      isRequired: false,
      elementType: "TIMEPICKER"
    },   //设备投运时间
    "moduleNum": {
      title: "电源模块数量",
      keys: "moduleNum",
      value: "",
      isRequired: true,
      elementType: "INPUT",
      rules:[{ required: true, trigger:'onSubmit'}]
    },   // 电源模块数量
    "powerSupplyMode": {
      title: "电源供电方式",
      keys: "powerSupplyMode",
      value: "",
      text: "",
      isRequired: true,
      elementType: "PICKER",
      optionsParams: {type: "POWER_SUPPLY_MODE"}, // 获取options需要的参数
      name:'powerSupplyMode',
      rules:[{ required: true, trigger:'onSubmit'}]
    },   // 电源模块数量
    "ethernetNum": {
      title: "以太网口数量",
      keys: "ethernetNum",
      value: "",
      isRequired: true,
      elementType: "INPUT",
      rules:[{ required: true, trigger:'onSubmit'}]
    },   // 设备顺序
    "portNum": {
      title: "2M口数量",
      keys: "portNum",
      value: "",
      isRequired: true,
      elementType: "INPUT",
      rules:[{ required: true, trigger:'onSubmit'}]
    },   // 设备顺序
    "lightNum": {
      title: "光口数量",
      keys: "lightNum",
      value: "",
      isRequired: true,
      elementType: "INPUT",
      rules:[{ required: true, trigger:'onSubmit'}]
    },   // 设备顺序"
    "comboNum": {
      title: "光电复用口数量",
      keys: "comboNum",
      value: "",
      isRequired: true,
      elementType: "INPUT",
      rules:[{ required: true, trigger:'onSubmit'}]
    },   // 设备顺序
  }
}
let fileTemplate = [
  {
    name: "EQUIPMENT.jpg",
    previewName: "正面照片",
    type: "EQUIPMENT",
    bgImg: require("../../../../static/img/lyqzm.png"),
    raw: null, // raw文件
    img: '', // 用来显示的照片
  },
  {
    name: "NAMEPLATE.jpg",
    previewName: "反面照片",
    type: "NAMEPLATE",
    bgImg: require("../../../../static/img/lyqfm.png"),
    raw: null, // raw文件
    img: '', // 用来显示的照片
  },
  {
    name: "OTHER.jpg",
    previewName: "其他照片",
    type: "OTHER",
    bgImg: require("../../../../static/img/bg_qita.png"),
    raw: null, // raw文件
    img: '', // 用来显示的照片
  },
];
import moment from "moment/moment";
import {Dialog, Toast} from "vant";
import navBar from '../../../../components/common/nav-bar'
import plateTitle from '../../../../components/business/plateTitle'
import config from "../../../../common/config";

import {mapGetters} from "vuex";
import axios from "axios";
export default {
  name: 'routerInformationPerfection',
  components: {navBar,plateTitle },
  props: {},
  data() {
    return {
      baseUrl: "", // 基础url
      currentData: {}, // 当前基本信息
      currentDate: "",
      minDate: new Date(0),
      showPicker: false,
      showTimePicker: false,
      showPreview: false,
      files: {}, // 照片map
      delList: [], // 被删除的列表，需要和后台交互
      defaultPickerIndex: 0, // picker默认选中索引
      currentPickerList: [], // 当前可选的项
      showCustomInput: false, // 是否在下拉框中显示自定义输入
      customInput: '', // 下拉框中自定义输入的内容
      type:'',
      objId:'',
      taskId:'',
      state:'',
      taskSiteId:'',
      taskSiteName:'',
      routerId:'',
    };
  },
  computed: {
    ...mapGetters(["userData"]),
  },
  watch: {},
  onLoad(option) {
    config.getOptions.then(res => {
      this.baseUrl = res.firstUrl;
    })
    this.type = option.type
    this.objId = option.objId
    this.taskId = option.taskId
    this.state = option.state
    this.taskSiteId = option.taskSiteId
    this.taskSiteName = option.taskSiteName
    this.currentData = JSON.parse(JSON.stringify(infoOptical_add));
    this.files = JSON.parse(JSON.stringify(fileTemplate));
    this.currentData.hideProps = {
      // 新增业务线  taskid还未带过来，所属站点暂时不能选，
      // parStationIdName: option.taskSiteId,   //所属站点
      taskId: option.taskId, //所属工单id    //必填
      siteid: option.taskSiteId, //所属站点
      sitename: option.taskSiteName, //所属站点name
      tourOperId: this.userData.userId, //巡检人ID  必填      userId放进来
      tourOperName: this.userData.userName, //巡检人名称    必填       userName放进来
      producerIdCustom:'',
      modelnumberCustom:'',
    }
    this.currentData.visibleProps.parStationIdName.value = this.taskSiteName
    this.getRouterBaseList()
  },
  methods: {
    goBack(){
      if(this.type === 'reEdit') {
        uni.navigateTo({
          url:`/pages/workBench/todoTask/routerPatrol/RouterTourDetails?objId=${this.objId}&taskSiteId=${this.taskSiteId}&state=${this.state}
          &taskId=${this.taskId}&taskSiteName=${this.taskSiteName}`
        })
      }else {
        uni.navigateTo({
          url: `/pages/workBench/todoTask/routerPatrol/routerVerify?objId=${this.objId}&taskSiteId=${this.taskSiteId}&state=${this.state}&taskId=${this.taskId}&taskSiteName=${this.taskSiteName}`,
        })
      }
    },
    checkInfo(item) {
      this.currentChangeItem = item.keys
    },
    checkPickerList (optionItem) {
      this.currentChangeItem = optionItem.keys;
      if(optionItem.elementType === "TIMEPICKER") {
        this.currentDate = this.currentData.visibleProps[this.currentChangeItem].text !== ""
            ? new Date(this.currentData.visibleProps[this.currentChangeItem].text)
            : new Date();
        this.showTimePicker = true;
      }
      // 下拉选项不为日期类型时，获取可选列表
      else {
        this.showCustomInput = false;
        this.customInput = "";
        // 选项为设备型号时，请求传参带入设备品牌
        if(this.currentChangeItem === "modelnumber") {
          if(this.currentData.visibleProps.producerId.value === "") {
            Dialog.alert({
              message: '请先选择设备品牌',
              theme: 'round-button',
            });
            return;
          } else {
            optionItem.optionsParams.pid = this.currentData.visibleProps.producerId.value;
          }
        }

        if (this.currentChangeItem === 'parRoom') {
          optionItem.optionsParams.pid = this.currentData.hideProps.siteid;
        }
        if(optionItem.keys === "equStatus") {
          this.$api.todoTaskApi.selectList_Optical({kdCode:'DEVICE_ROLE'}).then(res => {
            this.currentPickerList = res.data.list.map(item => {
              return {
                origin: item,
                text: item.NAME,
                value: item.BRIEFNAME,
              }
            });
            this.showPicker = true;
          });
        } else if (optionItem.keys === "powerSupplyMode"){
          // 选项为电源供电方式
          this.$api.todoTaskApi.selectList_Optical({kdCode:'POWER_SUPPLY_MODE'}).then(res => {
            this.currentPickerList = res.data.list.map(item => {
              return {
                origin: item,
                text: item.NAME,
                value: item.BRIEFNAME,
              }
            });
            this.showPicker = true;
          });
        } else {
          // 获取可选列表
          this.$api.todoTaskApi.selectList_equipment(optionItem.optionsParams).then(async res => {
            await (this.showPicker = true);
            this.currentPickerList = res.data.map((item, index) => {
              if (item.TOTAL === this.currentData.visibleProps[this.currentChangeItem].text) {
                this.defaultPickerIndex = index;
                this.$refs.picker.setColumnIndex(0, index);
              }
              return {
                text: item.TOTAL,
                value: item.VALUE,
              }
            });
            // 如果选项为设备型号/设备品牌时，可自定义
            if(this.currentChangeItem === 'modelnumber' || this.currentChangeItem === 'producerId') {
              this.currentPickerList.push({
                text: '其他',
                value: 'other',
              })
              // 如果请求回来的下拉列表不包含当前表单项
              let includes = res.data.some((item, index) => {
                return item.TOTAL === this.currentData.visibleProps[this.currentChangeItem].text
              })
              if (!includes) {
                // 如果当前表单项的值为空，picker默认选中第一项
                if(this.currentData.visibleProps[this.currentChangeItem].text === '') {
                  this.defaultPickerIndex = 0;
                  this.$refs.picker.setColumnIndex(0, 0);
                  // 如果下拉列表只有’其他‘，则显示自定义输入框
                  if (this.currentPickerList.length === 1) {
                    this.showCustomInput = true;
                  }
                }
                // 如果当前表单项的值不为空，picker默认选至'其他'，自定义值默认填入当前下拉项的值
                else {
                  this.showCustomInput = true;
                  this.defaultPickerIndex = this.currentPickerList.length - 1;
                  this.$refs.picker.setColumnIndex(0, this.currentPickerList.length - 1);
                  this.customInput = this.currentData.visibleProps[this.currentChangeItem].text;
                }
              }
            }
          });
        }
      }
    },
    inputBlur(value, item) {
      this.currentChangeItem = item.keys;
      this.currentData.visibleProps[this.currentChangeItem].value = value;
    },
    formatter(type, val) {
      if (type === 'year') return val + '年'
      if (type === 'month') return val + '月'
      if (type === 'day') return val + '日'
    },
    // picker确认选择(所有下拉)
    pickerConfirm(selectedOption) {
      if (this.currentChangeItem === 'begTim') {
        this.currentData.visibleProps[this.currentChangeItem].text = moment(selectedOption).format('YYYY-MM')
        this.showTimePicker = false
      } else {
        // 下拉列表不为空
        if (selectedOption !== undefined) {
          // 如果选择的设备品牌与上一次不同，设备型号清空
          if (this.currentChangeItem === "producerId" && selectedOption.value !== this.currentData.visibleProps.producerId.value) {
            this.currentData.visibleProps.modelnumber.text = "";
            this.currentData.visibleProps.modelnumber.value = "";
            this.currentData.hideProps.producerIdCustom = "";
            this.currentData.hideProps.modelnumberCustom = "";
          }
          // 如果选择的设备型号与上一次不同，清空自定义设备型号
          else if (this.currentChangeItem === "modelnumber" && selectedOption.value !== this.currentData.visibleProps.modelnumber.value) {
            this.currentData.hideProps.modelnumberCustom = "";
          }

          if (selectedOption.text === '其他') {
            this.currentData.visibleProps[this.currentChangeItem].value = selectedOption.value;
            this.currentData.visibleProps[this.currentChangeItem].text = this.customInput;
            this.currentData.hideProps[this.currentChangeItem + "Custom"] = this.customInput;
          } else {
            this.currentData.visibleProps[this.currentChangeItem].value = selectedOption.value;
            this.currentData.visibleProps[this.currentChangeItem].text = selectedOption.text;
          }
        }
        this.showPicker = false;
      }
    },
    // 清空已选
    pickerEmpty(selectedOption) {
      if (this.currentChangeItem === 'begTim') {
        this.showTimePicker = false
        this.currentData.visibleProps[this.currentChangeItem].text = ''
      }else {
        this.showPicker = false;
        this.currentData.visibleProps[this.currentChangeItem].text = "";
        this.currentData.visibleProps[this.currentChangeItem].value = "";
        if(selectedOption !== undefined) {
          selectedOption.text = "";
          selectedOption.value = "";
        }
        // 清空设备品牌，同时清空设备型号
        if (this.currentChangeItem === "producerId") {
          this.currentData.visibleProps.modelnumber.text = "";
          this.currentData.visibleProps.modelnumber.value = "";
          this.currentData.hideProps.producerIdCustom = "";
          this.currentData.hideProps.modelnumberCustom = "";
        }
        // 清空设备型号
        else if (this.currentChangeItem === "modelnumber") {
          this.currentData.hideProps.modelnumberCustom = "";
        }
      }
    },
    scanQrcode (item) {
      let _this = this
      wx.scanQRCode({
        desc:"scanQRCode desc",
        needResult: 1,
        scanType:["qrCode"],
        success:function(res){
          _this.currentData.visibleProps.picture.value = res.resultStr
        },
        error:function(res){
          console.log("scanQRCode error",res);
        }
      });
    },
    imageHandle (imgItem, imgIndex, handleType) {
      if (handleType === 'CHOOSE') {
        this.choosePhoto(imgItem, imgIndex);
      } else if (handleType === 'PREVIEW') {
        this.showPreview = true;
      } else if (handleType === 'DELETE') {
        Dialog.confirm({
          message: `是否确认删除${imgItem.previewName}`
        })
            .then(() => {
              this.$set(this.files, imgIndex, {
                ...this.files[imgIndex],
                raw: null,
                img: ''
              })
              this.delList.includes(imgItem.type) ? null: this.delList.push(imgItem.type);
              console.log(this.delList, "delete")

            })
            .catch(() => {
              // on cancel
            })
      }
    },
    choosePhoto(imgItem, index) {
      wx.chooseImage({
        count:3,
        sourceType: ['album','camera'],
        success: (chooseImageRes) => {
          this.h5_url_to_blob(chooseImageRes.localIds[0]).then(res => {
            this.$set(this.files, index, {
              ...this.files[index],
              raw: res,
              img: chooseImageRes.localIds[0]
            })

            if (this.delList.includes(imgItem.type)) {
              this.delList = this.delList.filter(item => {
                if (item === imgItem.type) {
                  return false;
                }

                return true;
              })
            }

          })
        }
      });
    },
    h5_url_to_blob(url) {
      return new Promise((resolve, reject) => {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, true);
        xhr.responseType = 'blob';
        xhr.onload = function(e) {
          if (this.status == 200) {
            var Blob = this.response;
            // console.log(myBlob)
            resolve(Blob)
            // myBlob现在是对象URL指向的blob。
          }
        };
        xhr.send();
      })
    },
    pickerChange (curOption, curValue) {
      this.showCustomInput = curValue.text === '其他';
    },
    getRouterBaseList () {
      this.$api.queryRouter({ routerid: this.objId }).then(res => {
        if (res.data.length!=0){
          Object.keys(this.currentData.visibleProps).forEach(key => {
            if (
                this.currentData.visibleProps[key].elementType === 'PICKER' ||
                this.currentData.visibleProps[key].elementType === 'TIMEPICKER'
            ) {
              this.currentData.visibleProps[key].value = res.data[0][key]

              let arr = ['dspLevel','equStatus','equlevel','modelnumber','parRoom','producerId','serilanum']
              if (arr.includes(key)){
                this.currentData.visibleProps[key].text = res.data[0][key+'Name']
              }else {
                this.currentData.visibleProps[key].text = res.data[0][key]
              }
            }else {
              this.currentData.visibleProps[key].value = res.data[0][key]
            }
            (key === "powerTechType") && (this.currentData.visibleProps[key].value = res.data.powerTechTypeId);
            (key === "accumProducer") && (this.currentData.visibleProps[key].value = res.data.accumProducerId);
          })
          Object.keys(this.currentData.otherProps).forEach(key => {
            this.currentData.otherProps[key] = res.data[key]
          })

          this.currentData.otherProps.remark = res.data[0].remark

          // this.currentData.tourInfoProps['tourOperResult'].value = serviceState_map[res.data[0].serviceState]
          this.currentData.tourInfoProps['tourOperName'].value = res.data[0].tourOperName
          this.currentData.tourInfoProps['tourTimStr'].value = moment(res.data[0].tourTim).format('YYYY-MM-DD HH:mm')
          console.log(res.data[0].files,213123)
          if(res.data[0].files.length === 0) {
            this.files = JSON.parse(JSON.stringify(fileTemplate));
          }else {
            this.files = this.files.map((item) => {
              return {
                ...item,
                img: res.data[0].files[item.type] ? this.baseUrl + res.data[0].files[item.type]: '',
              }
            })
          }
        }
      })
    },
    upload() {
      Toast.loading({
        duration:0,
        message: '加载中...',
        forbidClick: true,
      });
      let params = {
        ...this.currentData.hideProps,
        ...this.currentData.otherProps,
        objId:this.objId,
        ...Object.values(this.currentData.visibleProps).reduce((prev, item) => {
          if (item.elementType === "TIMEPICKER") {
            prev[item.keys] = item.text;
          } else {
            prev[item.keys] = item.value;
          }
          return prev
        }, {}),
      }
      let requestParams = {
        params: JSON.stringify(params),
        files: this.files
      }
      let param = new FormData() // 创建form对象
      this.files.forEach((file) => {
        if (file.raw) {
          param.append('files', file.raw, file.name)
        }
      });
      // param.append('files', this.filesRaw[0], '测试')  // 通过append向form对象添加数据
      param.append('params', requestParams.params) // 添加form表单中其他数据
      // 添加请求头
      let config = {
        headers: { 'Content-Type': 'multipart/form-data',Authorization: uni.getStorageSync('token') || '' }
      }
      let url = "";
      // #ifndef IGW
      url = "/ap/txksh/kosinManage/rest/api/router/updateRouter";
      // #endif
      // #ifdef IGW
      url = `${this.baseUrl}/txksh/kosinManage/rest/api/router/updateRouter`
      // #endif
      axios
          .post(
              url,
              param,
              config
          )
          .then(response => {
            Toast.clear();

            if(response.data.code == 0) {
              // 如果当前为巡视，且返回data为0，表示重复巡视
                Dialog.confirm({
                  title: "保存成功",
                  showCancelButton: false,
                }).then(() => {
                  Dialog.confirm({
                    message: '是否继续核查业务信息？'
                  }).then(() => {
                    uni.navigateTo({
                      url: `/pages/workBench/todoTask/routerPatrol/routerOperationalVerification?objId=${this.objId}&taskId=${this.taskId}&state=${this.state}&taskSiteId=${this.taskSiteId}&taskSiteName=${this.taskSiteName}`
                    });
                  }).catch(() => {
                    uni.navigateTo({
                      url: `/pages/workBench/todoTask/routerPatrol/routerPatrol?objId=${this.objId}&taskId=${this.taskId}&state=${this.state}&taskSiteId=${this.taskSiteId}&taskSiteName=${this.taskSiteName}`
                    });
                  })
                });
              } else {
              Dialog.alert({
                message: response.data.msg,
                theme: 'round-button',
              });
            }

          })
    },
  }
};
</script>
<style scoped lang="scss">
.router-wrap {
  height: 100vh;
  background-color: #f8f8f8;
  .header {
    position: sticky;
    top: 0;
    z-index: 9;
  }
  .van-preview-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    .van-swipe {
      width: 100%;
      height: 60%;
    }
    img {
      height: 90%;
    }
  }
  .main-container {
    height: calc(100vh - #{px2vh(423)});
    padding: px2vh(30) px2vw(30) 0 px2vw(30);
    overflow: auto;
    /deep/.van-field__label,
    /deep/.van-field__control:read-only,
    /deep/.van-field__body .van-field__control{
      font-size: px2vw(42);
    }
    /deep/.van-field__label {
      width: 10em;
    }
    .plate-title2 {
      margin: px2vh(30) 0;
    }
    .base-info-container, .result-info-container {
      border-radius: $border-radius-base;
      overflow: hidden;
      background-color: #FFFFFF;
    }
    .patrol-info-container {
      padding: px2vh(70) px2vw(50);
      font-size: px2vw(42);
      color: #666666;
      border-radius: $border-radius-base;
      overflow: hidden;
      background-color: #FFFFFF;

      /deep/.van-radio {
        margin-right: px2vw(139.5)
      }

      .image-wrap {
        width: 100%;
        display: flex;
        img {
          width: px2vw(215);
          height: px2vw(215);
          margin-right: px2vw(40);
          border-radius: px2vw(6);
        }

        .image-list {
          width: 100%;
          display: flex;
          .upload-button {
            width: px2vw(215);
            height: px2vw(215);
            background-size: cover;
            margin-right: px2vw(40);
            position: relative;
            .delete-icon {
              position: absolute;
              top: px2vw(-20);
              right: px2vw(-20);
              width: px2vw(40);
              height: px2vw(40);
              background-color: rgba(0, 0, 0, 0.7);
              border-radius: 50%;
              color: #fff;
              display: flex;
              justify-content: center;
              align-items: center;
            }
          }
        }

      }
    }
    .remark-info-container {
      padding: px2vh(70) px2vw(50);
      margin-bottom: px2vh(30);
      font-size: px2vw(42);
      color: #666666;
      border-radius: $border-radius-base;
      overflow: hidden;
      background-color: #FFFFFF;
      margin-top: px2vh(30);
      .remark-wrap {
        background-color: #FAFAFA;
        padding: px2vh(41) px2vw(56) px2vh(77) px2vw(55);
        border-radius: px2vw(20);
        .remark-text {
          height: px2vh(150);
        }
      }
    }

  }
  .van-button {
    margin: px2vh(60) auto;
    width: calc(100vw - #{px2vw(60)});
    height: px2vh(120);
    color: #fff;
    background-color: #417ADC;
    border: 1px solid #417ADC;
    border-radius: px2vh(60);
  }
}
</style>
